<span page-title>{{ 'New Repository' | translate }}</span>

<h3 translate>New Repository</h3>

<div data-block="content" class="row">
  <form name="repositoryForm" class="col-sm-5" novalidate role="form">
    <div>
      <h4 translate> Basic Information </h4>
      <div bst-form-group label="{{ 'Name' | translate }}">
        <input id="name"
               name="name"
               ng-model="repository.name"
               type="text"
               autofocus
               required/>
      </div>

      <div bst-form-group label="{{ 'Label' | translate }}">
        <input id="label"
               name="label"
               ng-model="repository.label"
               type="text"
               required/>
      </div>

      <div bst-form-group label="{{ 'Description' | translate }}">
        <textarea id="description"
                  name="description"
                  ng-model="repository.description"
                  type="text"/>
      </div>

      <div bst-form-group label="{{ 'Type' | translate }}">
        <select required
                id="content_type"
                name="content_type"
                ng-model="repository.content_type"
                ng-options="type.name as type.name.replace('_',' ') for type in repositoryTypes">
        </select>
      </div>

      <div bst-form-group label="{{ 'Restrict to Architecture' | translate }}" ng-show="repository.content_type === 'yum'">
        <select id="architecture_restricted"
                name="architecture_restricted"
                ng-model="repository.arch"
                ng-options="arch.id as arch.name for arch in architecture">
        </select>
      </div>

      <div
        bst-form-group label="{{ 'Restrict to OS version' | translate }}"
        ng-if="repository.content_type === 'yum'"
      >
       <select id="os_versions"
               name="os_versions"
               ng-model="repository.os_versions"
               ng-options="tag as tag.name for tag in osVersionsOptions track by tag.id">
       </select>
       <p class="help-block" translate>
         The repository will be enabled by default on content hosts with the selected OS version.
       </p>
      </div>

    </div>
    <div ng-show="repository.content_type !== undefined">
      <h4 translate> Sync Settings </h4>
      <div bst-form-group label="{{ 'Upstream URL' | translate }} ">
        <input id="url"
               name="url"
               ng-model="repository.url"
               type="text"/>
        <p class="help-block" ng-show="repository.content_type === 'docker'" translate>
          URL of the registry you want to sync. Example: https://registry-1.docker.io/ or https://quay.io/
        </p>
        <p class="help-block" ng-show="repository.content_type === 'ansible_collection'" translate>
          Content synced depends on the specifity of the URL and/or the optional requirements.yaml specified below <a class="fa fa-question-circle" ng-show="repository.content_type === 'ansible_collection'"
                                                                      uib-popover-html="collectionURLPopover" popover-class="popover-large" popover-trigger="'outsideClick'" popover-append-to-body="true" popover-title="Upstream URL">
        </a>
        </p>

      </div>

      <div ng-show="repository.content_type === 'ansible_collection'" bst-form-group label="{{ 'Requirements.yml' | translate }}">
        <textarea id="ansible_collection_requirements"
               name="ansible_collection_requirements"
               ng-model="repository.ansible_collection_requirements"
               rows="10"
               placeholder= "{{ 'You can upload a requirements.yml file below to auto-fill contents or paste contents of requirement.yml here' | translate }}"
               type="text"/>
      </div>

      <div class="form-group" ng-show="repository.content_type === 'ansible_collection'">
        <input id="requirementFile" type="file" name="file_path" onclick="this.value = null" onchange="angular.element(this).scope().handleFiles(this)"/>
        <p class="help-block" translate>Upload Requirements.yml file <a class="fa fa-question-circle" ng-show="repository.content_type === 'ansible_collection'"
                                                                        uib-popover-html="requirementPopover" popover-class="popover-large" popover-trigger="'outsideClick'" popover-append-to-body="true">
        </a></p>
      </div>

      <div ng-show="repository.content_type === 'ansible_collection'" bst-form-group label="{{ 'Auth URL' | translate }}">
        <input id="ansible_collection_auth_url"
               name="ansible_collection_auth_url"
               ng-model="repository.ansible_collection_auth_url"
               type="text"/>
        <p class="help-block" ng-show="repository.content_type === 'ansible_collection'" translate>
          The URL to receive a session token from, e.g. used with Automation Hub.
        </p>
      </div>

      <div ng-show="repository.content_type === 'ansible_collection'" bst-form-group label="{{ 'Auth Token' | translate }}">
        <input id="ansible_collection_auth_token"
               name="ansible_collection_auth_token"
               ng-model="repository.ansible_collection_auth_token"
               type="text"/>
        <p class="help-block" ng-show="repository.content_type === 'ansible_collection'" translate>
          The token key to use for authentication.
        </p>
      </div>

      <div ng-show="repository.content_type === 'deb'" bst-form-group label="{{ 'Releases' | translate }}">
        <input id="deb_releases"
               name="deb_releases"
               ng-model="repository.deb_releases"
               type="text"/>
        <p class="help-block" translate>
          Whitespace-separated list of releases (suite or codename) to sync from. Default: stable
        </p>
      </div>
      <div ng-show="repository.content_type === 'deb'" bst-form-group label="{{ 'Components' | translate }}">
        <input id="deb_comonents"
               name="deb_components"
               ng-model="repository.deb_components"
               type="text"/>
        <p class="help-block" translate>
          Whitespace-separated list of components to sync from (leave clear to sync all). Example: main
        </p>
      </div>
      <div ng-show="repository.content_type === 'deb'" bst-form-group label="{{ 'Architectures' | translate }}">
        <input id="deb_architectures"
               name="deb_architectures"
               ng-model="repository.deb_architectures"
               type="text"/>
        <p class="help-block" translate>
          Whitespace-separated list of processor architectures to filter the sync by. Example: amd64
        </p>
      </div>

      <div bst-form-group label="{{ 'Upstream Sync Policy' | translate }}"  ng-if="repository.content_type === 'ostree'">
        <select required
                id="ostree_upstream_sync_policy"
                name="ostree_upstream_sync_policy"
                ng-model="repository.ostree_upstream_sync_policy"
                ng-options="id as name for (id, name) in ostreeUpstreamSyncPolicies">
        </select>

        <input id="ostree_upstream_sync_depth"
               name="ostree_upstream_sync_depth"
               ng-model="repository.ostree_upstream_sync_depth"
               type="number"
               ng-disabled="repository.ostree_upstream_sync_policy !== 'custom'"/>
        <p class="help-block" translate>
          Choose one of the policy selections for downloading ostree content from upstream url during synchronization. Choose "Latest" for downloading the latest version of the upstream branch. Choose "All History" to download all available versions of the upstream repository (this may take a large amount of space). Choose "Custom Depth" and provide an number to indicate the number of prior versions of the upstream branch to download.
        </p>

      </div>


      <div bst-form-group label="{{ 'Upstream Repository Name' | translate }}"  ng-if="repository.content_type === 'docker'">
        <input id="docker_upstream_name"
               name="docker_upstream_name"
               ng-model="repository.docker_upstream_name"
               type="text"/>
        <p class="help-block" translate>
          Name of the upstream repository you want to sync. Example: 'quay/busybox' or 'fedora/ssh'.
        </p>

      </div>

      <div bst-form-group label="{{ 'Ignorable Content' | translate }}"  ng-if="repository.content_type === 'yum'">
        <select id="ignorable_content"
                name="ignorable_content"
                multiple="true"
                ng-model="repository.ignorable_content"
                ng-options="id as name for (id, name) in ignorableYumContentUnits">
        </select>

        <p class="help-block">
          <span translate>Select content units to ignore while synchronizing this repository.</span><br />
          <span translate>Use Ctrl-click to multi-select/deselect items.</span>
        </p>
      </div>

      <div class="checkbox">
        <label>
          <input id="verify_ssl_on_sync" name="verify_ssl_on_sync" ng-model="repository.verify_ssl_on_sync" type="checkbox"/>
          <span translate>Verify SSL</span>
        </label>

        <p class="help-block" translate>
          Selecting this option will result in Katello verifying that the upstream url's SSL certificates are signed by a trusted CA. Unselect if you do not want this verification.
        </p>
      </div>


      <div bst-form-group label="{{ 'Upstream Username' | translate }}" >
        <input id="upstream_username"
               name="upstream_username"
               ng-model="repository.upstream_username"
               type="text"/>
        <p class="help-block" translate>
          Username of the upstream repository user for authentication. Leave empty if repository does not require authentication.
        </p>
      </div>

      <div bst-form-group label="{{ 'Upstream Password' | translate }}" >
        <input id="upstream_password"
               name="upstream_password"
               ng-model="repository.upstream_password"
               type="password"/>
        <p class="help-block" translate>
          Password of the upstream repository user for authentication. Leave empty if repository does not require authentication.
        </p>
      </div>

      <div bst-form-group label="{{ 'Download Policy' | translate }}" ng-if="repository.content_type === 'yum'">
        <select id="download_policy"
                name="download_policy"
                ng-model="repository.download_policy"
                ng-options="id as name for (id, name) in downloadPolicies">
        </select>
        <p class="help-block" translate>
          For On Demand synchronization, only the metadata is downloaded during sync and packages are fetched and stored on the filesystem when clients request them.
          On Demand is not recommended for custom repositories unless the upstream repository maintains older versions of packages within the repository.
          The Immediate option will download all metadata and packages immediately during the sync.
        </p>
      </div>

      <div class="checkbox" ng-hide="repository.content_type === 'ostree'">
        <label>
          <input id="mirror_on_sync" name="mirror_on_sync" ng-model="repository.mirror_on_sync" type="checkbox"/>
          <span translate>Mirror on Sync</span>
        </label>

        <p class="help-block" translate>
          Selecting this option will result in contents that are no longer part of the upstream repository being removed during synchronization.
        </p>
      </div>

      <div bst-form-group label="{{ 'HTTP Proxy Policy' | translate }}">
        <select required
                id="http_proxy_policy"
                name="http_proxy_policy"
                ng-model="repository.http_proxy_policy"
                ng-options="type.label as type.name for type in policies">
        </select>
      </div>
      <span ng-show="repository.http_proxy_policy === 'use_selected_http_proxy'">
        <div bst-form-group label="{{ 'HTTP Proxy' | translate }}">
          <span translate ng-show="proxies.length == 0">
            No HTTP Proxies found
          </span>
          <select
              id="http_proxy"
              name="http_proxy"
              ng-model="repository.http_proxy_id"
              ng-options="proxy.id as proxy.name for proxy in proxies"
              ng-show="proxies.length > 0">
          </select>
        </div>
      </span>
    </div>

    <div ng-show="repository.content_type === 'yum' || repository.content_type === 'deb' || repository.content_type === 'file'">
      <h4 ng-show="repository.content_type !== undefined" translate> Published Repository Information </h4>

      <div bst-form-group label="{{ 'Checksum' | translate }}" ng-show="repository.content_type === 'yum'">
        <select id="checksum_type"
                name="checksum_type"
                ng-model="repository.checksum_type"
                ng-options="type.id as type.name for type in checksums">
        </select>
        <p class="help-block" translate>
          For older operating systems such as Red Hat Enterprise Linux 5 or CentOS 5 it is recommended to use sha1.
        </p>
      </div>

      <div class="checkbox">
        <label>
          <input id="unprotected" name="unprotected" ng-model="repository.unprotected" type="checkbox"/>
          <span translate>Publish via HTTP</span>
        </label>
      </div>

      <div bst-form-group label="{{ 'GPG Key' | translate }}" ng-show="repository.content_type === 'yum' || repository.content_type === 'deb'">
        <select id="gpg_key_id"
                name="gpg_key_id"
                ng-model="repository.gpg_key_id"
                ng-options="content_credential.id as content_credential.name for content_credential in contentCredentials | filter: { 'content_type': 'gpg_key' }">
          <option value=""></option>
        </select>
      </div>

      <div bst-form-group label="{{ 'SSL CA Cert' | translate }}">
        <select id="ssl_ca_cert_id"
                name="ssl_ca_cert_id"
                ng-model="repository.ssl_ca_cert_id"
                ng-options="content_credential.id as content_credential.name for content_credential in contentCredentials | filter: { 'content_type': 'cert' }">
          <option value=""></option>
        </select>
      </div>

      <div bst-form-group label="{{ 'SSL Client Cert' | translate }}">
        <select id="ssl_client_cert_id"
                name="ssl_client_cert_id"
                ng-model="repository.ssl_client_cert_id"
                ng-options="content_credential.id as content_credential.name for content_credential in contentCredentials | filter: { 'content_type': 'cert' }">
          <option value=""></option>
        </select>
      </div>

      <div bst-form-group label="{{ 'SSL Client Key' | translate }}">
        <select id="ssl_client_key_id"
                name="ssl_client_key_id"
                ng-model="repository.ssl_client_key_id"
                ng-options="content_credential.id as content_credential.name for content_credential in contentCredentials | filter: { 'content_type': 'cert' }">
          <option value=""></option>
        </select>
      </div>
    </div>

    <div bst-form-buttons ng-show="repository.content_type !== undefined"
         on-cancel="transitionTo('product.repositories', {productId: repository.product_id})"
         on-save="save(repository)"
         working="working">
    </div>
  </form>
</div>
